import mongoose from 'mongoose';
import { ICheckList } from '@/types/model';

const CheckListSchema = new mongoose.Schema<ICheckList>({
    checkListId: { type: String, required: true, unique: true },
    cardId: { type: String, required: true },
    title: { type: String, required: true },
    createdAt: { type: Number, default: Date.now },
    updatedAt: { type: Number, default: Date.now }
}, {
    id: false,
    collection: 'checklists',
    toJSON: { 
        getters: true, 
        virtuals: false,
        transform: (doc, ret) => {
            delete ret._id;
            delete ret.__v;
            return ret;
        }
    },
    toObject: { 
        getters: true, 
        virtuals: false,
        transform: (doc, ret) => {
            delete ret._id;
            delete ret.__v;
            return ret;
        }
    }
});

CheckListSchema.pre('save', function (next) {
    this.updatedAt = Date.now();
    next();
});

export const CheckList = mongoose.model<ICheckList>('CheckList', CheckListSchema);
